home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / GAPLib.lha / GAPLib / examples / FitnessExample.t next >
Encoding:
Text File  |  1999-05-22  |  914 b   |  37 lines

  1.  
  2. /*
  3.  * This is an example template file for the GAP Conjurer. The GAP Conjurer
  4.  * is a source wizard accompanying GAP-Lib.
  5.  *
  6.  * After processing the following substitutions will be made: 
  7.  *
  8.  * $N => Name of the current type of individual. eg. "Polyphant"
  9.  *
  10.  * $I => Index of the current population. eg. "0"
  11.  *
  12.  * $$ => A single dollar sign.
  13.  *
  14.  * There should be no other occurences of dollar signs in the template file.
  15.  *
  16.  *
  17.  * The example fitness function is simply the hamming distance (the number
  18.  * of differing bits) between the genome bitstring and the constant string
  19.  * "\xAA\xAA\xAA\xAA" which has every other bit set and every other clear.
  20.  *
  21.  *
  22.  * The negation is because GAP-Lib sees higher fitness as better, and the
  23.  * 4 is the length of the bitstring.
  24.  *
  25.  */
  26.  
  27.  
  28. double $NFitness(struct $N *Polly)
  29. {
  30. double fitness;
  31.  
  32. fitness = -HammingDist(Polly->Data,"\xAA\xAA\xAA\xAA",4);
  33.  
  34. return(fitness);
  35. }
  36.  
  37.